<template>
  <div class="base-sign-up">
    <van-nav-bar
      title="注册"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
      safe-area-inset-top
    />
    <van-form @submit="onSubmit">
      <van-field
        v-if="isshow"
        v-model="formdata.idcard"
        name="idcard"
        label="身份证号"
        placeholder="身份证号"
        :rules="[{ required: true, message: '请填写身份证号' }]"
      />
      <van-field
        v-if="isshow"
        v-model="formdata.password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '密码' }]"
      />
      <van-field
        v-if="isshow"
        v-model="formdata.tel"
        name="tel"
        label="电话号码"
        placeholder="电话号码"
        :rules="[{ required: true, message: '请填写电话号码' }]"
      />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">注册</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
export default {
  name: "signup",
  data () {
    return {
      isshow: true,
      formdata:{
        idcard:'111111111111111111',
        password: '888888',
        tel: '123456789',
      }
    };
  },
  methods: {
    onSubmit(values) {
      console.log(values);
      this.HttpManager.users_signup(values)
        .then((res) => {
          if(res.code === 0){
            this.$notify({ type: "success", message: "注册成功" });
            this.$router.push("Login");
          }else{
            this.$notify({ type: "danger", message: res.msg });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onClickLeft(){
      this.$router.go(-1);
    },
  }
}
</script>

<style lang="less" scoped>
  .base-sign-up {
    height: 100%;
  }
</style>
